package com.jay.media.video.openglesdemo

import android.content.Context
import android.opengl.GLSurfaceView
import android.util.AttributeSet
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

/**
 * @author xuzhou4
 * @date 2022/2/9
 */
class MyGLSurfaceView @JvmOverloads constructor(context: Context, attrs: AttributeSet) :
    GLSurfaceView(context, attrs) {

    private var mNativeRenderer: MyNativeRenderer
    private var mGLRenderer: MyGLRenderer

    init {
        this.setEGLContextClientVersion(3)
        mNativeRenderer = MyNativeRenderer()
        mGLRenderer = MyGLRenderer(mNativeRenderer)
        setRenderer(mGLRenderer)
        renderMode = RENDERMODE_CONTINUOUSLY
    }

    inner class MyGLRenderer(var myNativeRenderer: MyNativeRenderer) : Renderer {
        override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
            myNativeRenderer.native_onSurfaceCreated()
        }

        override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
            myNativeRenderer.native_onSurfaceChanged(width, height)
        }

        override fun onDrawFrame(gl: GL10?) {
            myNativeRenderer.native_onDrawFrame()
        }
    }
}